﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using V5_BLL;
using V5_Model;
using V5_Common;
using V5_EShop._Class.Common;

namespace V5_EShop.Admin {
    public partial class Admin_TemplateSelect : BasicPage {
        protected void Page_Load(object sender, EventArgs e) {
            if (!this.IsPostBack) {
                this.Bind_dlList();
            }
        }

        /// <summary>
        /// 绑定所有模板
        /// </summary>
        private void Bind_dlList() {
            this.dlList.DataSource = new BLLTemplate(Server.MapPath("~/Templates/")).GetAllTemplateInfo();
            this.dlList.DataBind();
        }

        /// <summary>
        /// 设置为默认模板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSetTemplateShow_Click(object sender, EventArgs e) {
            string templatePath;
            BLLConfig bllconfig = new BLLConfig();
            ModelConfig modelconfig = bllconfig.GetModel();
            foreach (DataListItem item in this.dlList.Items) {
                RadioButton rbtn = (RadioButton)item.FindControl("rbtnSelect");
                if (rbtn.Checked == true && rbtn.Enabled == true) {
                    Label lbl = (Label)item.FindControl("lblName");
                    templatePath = lbl.ToolTip;
                    modelconfig.TemplatePath = templatePath;//修改模板
                    bllconfig.Update(modelconfig);
                }
            }
            Response.Redirect("Admin_TemplateSelect.aspx");
            //this.Bind_dlList();
            //Pr.RegClientAlertAndRedirect(this, "模板选择成功!", "Admin_TemplateSelect.aspx");
        }

        /// <summary>
        /// 绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void dlList_ItemDataBound(object sender, DataListItemEventArgs e) {
            RadioButton rbtnSelect = (RadioButton)e.Item.FindControl("rbtnSelect");
            Label lbltemplatePath = (Label)e.Item.FindControl("lblName");
            if (lbltemplatePath.ToolTip.Trim() == SiteHelper.TemplateDir) {
                rbtnSelect.Checked = true;
                rbtnSelect.Enabled = false;
            }
        }
    }
}
